﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using UniRx;
using UniRx.Triggers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005C0 RID: 1472
	public class OutsideSoundControl : MonoBehaviour
	{
		// Token: 0x0600257D RID: 9597 RVA: 0x000DE0E4 File Offset: 0x000DC2E4
		private void OnClickRepeat()
		{
			Singleton<Studio>.Instance.outsideSoundCtrl.repeat = ((Singleton<Studio>.Instance.outsideSoundCtrl.repeat != BGMCtrl.Repeat.None) ? BGMCtrl.Repeat.None : BGMCtrl.Repeat.All);
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.outsideSoundCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
		}

		// Token: 0x0600257E RID: 9598 RVA: 0x000DE150 File Offset: 0x000DC350
		private void OnClickStop()
		{
			Singleton<Studio>.Instance.outsideSoundCtrl.Stop();
		}

		// Token: 0x0600257F RID: 9599 RVA: 0x000DE164 File Offset: 0x000DC364
		private void OnClickPlay()
		{
			Singleton<Studio>.Instance.outsideSoundCtrl.Play();
		}

		// Token: 0x06002580 RID: 9600 RVA: 0x000DE178 File Offset: 0x000DC378
		private void OnClickPause()
		{
		}

		// Token: 0x06002581 RID: 9601 RVA: 0x000DE17C File Offset: 0x000DC37C
		private void OnClickExpansion()
		{
			this.objBottom.SetActive(!this.objBottom.activeSelf);
			this.buttonExpansion.image.sprite = this.spriteExpansion[(!this.objBottom.activeSelf) ? 0 : 1];
		}

		// Token: 0x06002582 RID: 9602 RVA: 0x000DE1D0 File Offset: 0x000DC3D0
		private void OnClickSelect(int _idx)
		{
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = false;
			}
			this.select = _idx;
			if (this.select != -1)
			{
				Singleton<Studio>.Instance.outsideSoundCtrl.fileName = this.listPath[_idx];
			}
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x06002583 RID: 9603 RVA: 0x000DE24C File Offset: 0x000DC44C
		private void InitList()
		{
			for (int i = 0; i < this.transformRoot.childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			IEnumerable<string> files = Directory.GetFiles(UserData.Create("audio"), "*.wav");
			if (OutsideSoundControl.callback0 == null)
			{
				OutsideSoundControl.callback0 = new Func<string, string>(Path.GetFileName);
			}
			this.listPath = files.Select(OutsideSoundControl.callback0).ToList<string>();
			int count = this.listPath.Count;
			for (int j = 0; j < count; j++)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectNode);
				gameObject.transform.SetParent(this.transformRoot, false);
				StudioNode component = gameObject.GetComponent<StudioNode>();
				component.active = true;
				int idx = j;
				component.addOnClick = delegate()
				{
					this.OnClickSelect(idx);
				};
				component.text = Path.GetFileNameWithoutExtension(this.listPath[j]);
				this.dicNode.Add(idx, component);
			}
			this.select = this.listPath.FindIndex((string v) => v == Singleton<Studio>.Instance.outsideSoundCtrl.fileName);
			StudioNode studioNode = null;
			if (this.dicNode.TryGetValue(this.select, out studioNode))
			{
				studioNode.select = true;
			}
		}

		// Token: 0x06002584 RID: 9604 RVA: 0x000DE3CC File Offset: 0x000DC5CC
		private void Awake()
		{
			this.buttonRepeat.onClick.AddListener(new UnityAction(this.OnClickRepeat));
			this.buttonStop.onClick.AddListener(new UnityAction(this.OnClickStop));
			this.buttonPlay.onClick.AddListener(new UnityAction(this.OnClickPlay));
			this.buttonPause.onClick.AddListener(new UnityAction(this.OnClickPause));
			this.buttonExpansion.onClick.AddListener(new UnityAction(this.OnClickExpansion));
			this.InitList();
			this.UpdateAsObservable().Subscribe(delegate(Unit _)
			{
				this.imagePlayNow.enabled = Singleton<Studio>.Instance.outsideSoundCtrl.play;
			});
		}

		// Token: 0x06002585 RID: 9605 RVA: 0x000DE484 File Offset: 0x000DC684
		private void OnEnable()
		{
			this.buttonRepeat.image.sprite = this.spriteRepeat[(Singleton<Studio>.Instance.outsideSoundCtrl.repeat != BGMCtrl.Repeat.None) ? 1 : 0];
		}

		// Token: 0x040025EE RID: 9710
		[SerializeField]
		private GameObject objectNode;

		// Token: 0x040025EF RID: 9711
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x040025F0 RID: 9712
		[SerializeField]
		private Button buttonRepeat;

		// Token: 0x040025F1 RID: 9713
		[SerializeField]
		private Sprite[] spriteRepeat;

		// Token: 0x040025F2 RID: 9714
		[SerializeField]
		private Button buttonStop;

		// Token: 0x040025F3 RID: 9715
		[SerializeField]
		private Button buttonPlay;

		// Token: 0x040025F4 RID: 9716
		[SerializeField]
		private Image imagePlayNow;

		// Token: 0x040025F5 RID: 9717
		[SerializeField]
		private Button buttonPause;

		// Token: 0x040025F6 RID: 9718
		[SerializeField]
		private Button buttonExpansion;

		// Token: 0x040025F7 RID: 9719
		[SerializeField]
		private Sprite[] spriteExpansion;

		// Token: 0x040025F8 RID: 9720
		[SerializeField]
		private GameObject objBottom;

		// Token: 0x040025F9 RID: 9721
		private List<string> listPath = new List<string>();

		// Token: 0x040025FA RID: 9722
		private Dictionary<int, StudioNode> dicNode = new Dictionary<int, StudioNode>();

		// Token: 0x040025FB RID: 9723
		private int select = -1;

		// Token: 0x040025FC RID: 9724
		[CompilerGenerated]
		private static Func<string, string> callback0;
	}
}
